﻿Imports VN.INS.BL.BC
Imports System.Data

Partial Class Devida_ProgFinanciero
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'captura de parametros
        If (Not (Page.IsPostBack)) Then
            ViewState("POA") = Request.QueryString("Param").ToString
            ViewState("NomEjecutor") = Request.QueryString("NomEjecutor").ToString
            ViewState("NomProyAct") = Request.QueryString("NomProyAct").ToString


            lblNomProyAct.Text = "ACTIVIDAD/PROYECTO: " + ViewState("NomProyAct")
            lblNomEjecutor.Text = "EJECUTOR: " + ViewState("NomEjecutor")
            lblPoa.Text = ViewState("POA")

            lblPoaImp.Text = lblPoa.Text
            carga_grilla(ViewState("POA"))
        End If
    End Sub
    
    Public Sub carga_grilla(ByVal POA As String)
        Dim objFinancieroBC As ProgFinanBC = New ProgFinanBC
        Dim dtFinanciero As DataTable
        'llenado de grilla financiera
        dtFinanciero = objFinancieroBC.ListaProgramacion(POA)
        gv_Detalle.DataSource = dtFinanciero
        gv_Detalle.DataBind()

        gv_doc.DataSource = dtFinanciero
        gv_doc.DataBind()
    End Sub

    Dim Total_Mes_1 As Decimal = 0
    Dim Total_Mes_2 As Decimal = 0
    Dim Total_Mes_3 As Decimal = 0
    Dim Total_Mes_4 As Decimal = 0
    Dim Total_Mes_5 As Decimal = 0
    Dim Total_Mes_6 As Decimal = 0
    Dim Total_Mes_7 As Decimal = 0
    Dim Total_Mes_8 As Decimal = 0
    Dim Total_Mes_9 As Decimal = 0
    Dim Total_Mes_10 As Decimal = 0
    Dim Total_Mes_11 As Decimal = 0
    Dim Total_Mes_12 As Decimal = 0
    Dim Total As Decimal = 0

    Protected Sub gv_Detalle_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gv_Detalle.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim Aux1 As Decimal = If(e.Row.Cells(2).Text.ToString = "" Or e.Row.Cells(2).Text.ToString = "&nbsp;" Or IsDBNull(e.Row.Cells(2).Text.ToString), 0, Convert.ToDecimal(e.Row.Cells(2).Text.ToString))
            Dim Aux2 As Decimal = If(e.Row.Cells(3).Text.ToString = "" Or e.Row.Cells(3).Text.ToString = "&nbsp;" Or IsDBNull(e.Row.Cells(3).Text.ToString), 0, Convert.ToDecimal(e.Row.Cells(3).Text.ToString))
            Dim Aux3 As Decimal = If(e.Row.Cells(4).Text.ToString = "" Or e.Row.Cells(4).Text.ToString = "&nbsp;" Or IsDBNull(e.Row.Cells(4).Text.ToString), 0, Convert.ToDecimal(e.Row.Cells(4).Text.ToString))
            Dim Aux4 As Decimal = If(e.Row.Cells(5).Text.ToString = "" Or e.Row.Cells(5).Text.ToString = "&nbsp;" Or IsDBNull(e.Row.Cells(5).Text.ToString), 0, Convert.ToDecimal(e.Row.Cells(5).Text.ToString))
            Dim Aux5 As Decimal = If(e.Row.Cells(6).Text.ToString = "" Or e.Row.Cells(6).Text.ToString = "&nbsp;" Or IsDBNull(e.Row.Cells(6).Text.ToString), 0, Convert.ToDecimal(e.Row.Cells(6).Text.ToString))
            Dim Aux6 As Decimal = If(e.Row.Cells(7).Text.ToString = "" Or e.Row.Cells(7).Text.ToString = "&nbsp;" Or IsDBNull(e.Row.Cells(7).Text.ToString), 0, Convert.ToDecimal(e.Row.Cells(7).Text.ToString))
            Dim Aux7 As Decimal = If(e.Row.Cells(8).Text.ToString = "" Or e.Row.Cells(8).Text.ToString = "&nbsp;" Or IsDBNull(e.Row.Cells(8).Text.ToString), 0, Convert.ToDecimal(e.Row.Cells(8).Text.ToString))
            Dim Aux8 As Decimal = If(e.Row.Cells(9).Text.ToString = "" Or e.Row.Cells(9).Text.ToString = "&nbsp;" Or IsDBNull(e.Row.Cells(9).Text.ToString), 0, Convert.ToDecimal(e.Row.Cells(9).Text.ToString))
            Dim Aux9 As Decimal = If(e.Row.Cells(10).Text.ToString = "" Or e.Row.Cells(10).Text.ToString = "&nbsp;" Or IsDBNull(e.Row.Cells(10).Text.ToString), 0, Convert.ToDecimal(e.Row.Cells(10).Text.ToString))
            Dim Aux10 As Decimal = If(e.Row.Cells(11).Text.ToString = "" Or e.Row.Cells(11).Text.ToString = "&nbsp;" Or IsDBNull(e.Row.Cells(11).Text.ToString), 0, Convert.ToDecimal(e.Row.Cells(11).Text.ToString))
            Dim Aux11 As Decimal = If(e.Row.Cells(12).Text.ToString = "" Or e.Row.Cells(12).Text.ToString = "&nbsp;" Or IsDBNull(e.Row.Cells(12).Text.ToString), 0, Convert.ToDecimal(e.Row.Cells(12).Text.ToString))
            Dim Aux12 As Decimal = If(e.Row.Cells(13).Text.ToString = "" Or e.Row.Cells(13).Text.ToString = "&nbsp;" Or IsDBNull(e.Row.Cells(13).Text.ToString), 0, Convert.ToDecimal(e.Row.Cells(13).Text.ToString))
            Dim AuxTotal As Decimal = If(e.Row.Cells(14).Text.ToString = "" Or e.Row.Cells(14).Text.ToString = "&nbsp;" Or IsDBNull(e.Row.Cells(14).Text.ToString), 0, Convert.ToDecimal(e.Row.Cells(14).Text.ToString))

            Total_Mes_1 += Aux1
            Total_Mes_2 += Aux2
            Total_Mes_3 += Aux3
            Total_Mes_4 += Aux4
            Total_Mes_5 += Aux5
            Total_Mes_6 += Aux6
            Total_Mes_7 += Aux7
            Total_Mes_8 += Aux8
            Total_Mes_9 += Aux9
            Total_Mes_10 += Aux10
            Total_Mes_11 += Aux11
            Total_Mes_12 += Aux12
            Total += AuxTotal

        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(1).Text = "TOTALES"

            'Total por mes
            e.Row.Cells(2).Text = (Total_Mes_1).ToString("#,0.00")
            e.Row.Cells(3).Text = (Total_Mes_2).ToString("#,0.00")
            e.Row.Cells(4).Text = (Total_Mes_3).ToString("#,0.00")
            e.Row.Cells(5).Text = (Total_Mes_4).ToString("#,0.00")
            e.Row.Cells(6).Text = (Total_Mes_5).ToString("#,0.00")
            e.Row.Cells(7).Text = (Total_Mes_6).ToString("#,0.00")
            e.Row.Cells(8).Text = (Total_Mes_7).ToString("#,0.00")
            e.Row.Cells(9).Text = (Total_Mes_8).ToString("#,0.00")
            e.Row.Cells(10).Text = (Total_Mes_9).ToString("#,0.00")
            e.Row.Cells(11).Text = (Total_Mes_10).ToString("#,0.00")
            e.Row.Cells(12).Text = (Total_Mes_11).ToString("#,0.00")
            e.Row.Cells(13).Text = (Total_Mes_12).ToString("#,0.00")

            'Total total
            e.Row.Cells(14).Text = (Total).ToString("#,0.00")

        End If
    End Sub

    Protected Sub btn_salir_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_salir.Click
        'volver a pagina principal
        Response.Redirect("listaPOAs.aspx")
    End Sub

End Class
